package com.renrenyou.duanshipin.home;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.renrenyou.duanshipin.login.PolicyDialog;
import com.renrenyou.duanshipin.util.SharedPref;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        // 设置浅色状态栏文字 (深色背景)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
            );
        }
        super.onCreate(savedInstanceState);

        int installStatus = SharedPref.getInstance().getInt("install", -1);
        if (installStatus == -1) {
            showPolicyDialog();
        } else {
            startActivity(new Intent(SplashActivity.this, MainActivity.class));
            finish();
        }
    }

    private void showPolicyDialog() {
        PolicyDialog dialog = new PolicyDialog(this);
        dialog.setOnPositiveListener(new PolicyDialog.PositiveCallback() {
            @Override
            public void onPositive() {
                dialog.dismiss();
                SharedPref.getInstance().putInt("install", 0);
                startActivity(new Intent(SplashActivity.this, MainActivity.class));
                finish();
            }

            @Override
            public void onNegative() {
                dialog.dismiss();
                finish();
            }
        });
        dialog.show();
    }
}
